﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <link href="~/X-admin/lib/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/theme123.min.css" rel="stylesheet" />
    <!-- <link rel="stylesheet" href="./css/theme5.css"> -->
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="#">首页</a>
            @*<a href="">演示</a>*@
            <a>
                <cite>工程管理</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    @*@Html.Partial("~/Views/Mange/common/upload.cshtml");*@
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card" style="min-height:500px;">
                    <div class="layui-card-body " style="float: left;margin-right:40px;">
                        <form class="layui-form layui-col-space7">
                            @*<div class="layui-inline layui-show-xs-block">
                                    <input  class="layui-input" autocomplete="off" placeholder="开始日" name="createDate" id="start">
                                </div>*@

                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="project" placeholder="请输入项目名称" autocomplete="off" class="layui-input" style="padding: 0px 30px;" id="keywords">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach" style="cursor:pointer;"><i class="layui-icon">&#xe615;</i></button>
                                @*<button class="layui-btn layui-btn-normal" style="cursor:pointer;" id="resetBtn">重置</button>*@
                            </div>
                        </form>
                    </div>
                    <div class="layui-cards" style="height:48px;line-height:48px;">
                        @*<button class="layui-btn" id="add"><i class="layui-icon"></i>添加</button>*@
                    </div>
                    <div style="clear:both;"></div>

                    <div class="layui-card-body ">
                        <table class="layui-table layui-form">

                            <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>项目名称</th>
                                    <th>创建日期</th>
                                </tr>
                            </thead>
                            <tbody id="renderList"></tbody>
                        </table>
                        <div id="laypage"></div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    @* 弹出层 *@
    <div id="showMsg" class="showMsg" style="display:none;">
        <form class="layui-form" action="#" style="margin-top:17px;">
            <div class="layui-form-item">
                <label class="layui-form-label">项目名称:</label>
                <div class="layui-input-block">
                    <input type="text" name="project" required lay-verify="required" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                </div>
            </div>
        </form>
    </div>

    <script>
    layui.use(['laydate', 'form', 'upload', 'jquery', 'laypage'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        var upload = layui.upload;
        var $ = layui.jquery;
        var laypage = layui.laypage;


        //渲染列表
        function List() {

        }
        List.prototype = {
            init: function (pageNo, pageSize) {
                this.pageNo = pageNo;
                this.pageSize = pageSize;
            },
            render: function (cb) {
                var that =this;
                $.post('/Home/list', {
                    pageNo: this.pageNo,
                    pageSize: this.pageSize,
                    keywords: $("#keywords").val().trim()
                }, function (res) {
                    var strhtml = "";
                    var data = JSON.parse(res.data);
                    var total = res.total;
                    if (data.length != 0) {
                        $.each(data, function (index, item) {
                           // var btn = '<a href="javascript:;" class="deletePro" style="color:#f32323;" data-id="' + item.projectid + '" data-name="'+item.name+'">删除 <img src="/Content/img/delete.png" width="15"/></a>';
                            strhtml += '<tr ><td>' + (index + 1) + '</td>' +
                                       '<td><a href="#" class="showMsg" data-csid="' + item.projectid + '" data-id="' + item.id + '" style="color:blue;">' + item.name + '</a></td>' +
                                         '<td>' + (item.createDate == null ? "-" : item.createDate.split('T')[0]) + '</td>' +
                                         
                                '</tr>';
                        });
                        $("#renderList").html(strhtml);
                        laypage.render({
                            elem: 'laypage', //注意，这里的 test1 是 ID，不用加 # 号
                            count: total, //数据总数，从服务端得到
                            limit: that.pageSize,
                            curr: that.pageNo || 1,
                            jump: function (obj, first) {
                                console.log(obj.curr);
                                if (!first) {
                                    var curr = obj.curr;
                                    that.init(curr, that.pageSize);
                                    that.render();
                                }

                            }
                        });
                    } else {
                        $("#renderList").html('<tr><td colspan="3">暂无数据</td></tr>');
                    }
                })
            },
            //分页
            search:function(){

            }
        }
        //分页
        var list = new List();
        list.init(1, 10);
        list.render(function (total) {
            list.page(total);
        });

        //查询
        form.on('submit(sreach)', function () {
            list.init(1, 10);
            list.render(function (total) {
                list.page(total);
            });
            return false;
        })
        //删除项目
        $("#renderList").on('click', '.deletePro', function () {
            var id = $(this).attr('data-id');
            var name = $(this).attr('data-name');
            layer.confirm('是否确认删除项目及文件？', { icon: 3, title: '提示' }, function (layerIndex) {
                $.post('/Home/deleteProject', {id:id,name:name}, function (res) {
                    var data = JSON.parse(res);
                    if (data.success) {
                        layer.msg(data.msg, function () {
                            var list = new List();
                            list.init(1, 10);
                            list.render(function (total) {
                                list.page(total);
                            });
                            layer.closeAll();
                        })
                    } else {
                        layer.msg(data.msg)
                    }
                })
            })
        })
        //重置
        $("#resetBtn").on('click', function () {
            //$("#keywords").val("");
            //list.init(1, 10);
            //list.render(function (total) {
            //    list.page(total);
            //});

            parent.xadmin.add_tab('测试', '/Login/Index');
          //  parent.location.href = '/Home/Index';
        })
        uploadFile("#demand");  //上传需求
        uploadFile("#manage");  //上传管理
        uploadFile("#electric");  //上传电气
        uploadFile("#machine");  //上传机械图纸
        uploadFile("#software");  //上传软件
        function uploadFile(id) {
           upload.render({
                elem: id //绑定元素
           , url: '/Upload/Upload' //上传接口
            , accept: 'file'
             , before: function (obj) {
                 $.extend(true, this.data, {
                     name: $(this.elem).attr('x_title')
                 });
             }
           , done: function (res) {
               //上传完毕回调
               console.log(res)
               if (res.Success) {
                   layer.msg('上传成功', { icon: 6 }, function () {

                   });
                   var item = this.item;
                   $(item).parents(".layui-form-item").find("input.hiddenFile").val(res.filePath);
                   $(item).parents(".layui-form-item").find("input.hiddenName").val(res.FileName);
                   $(item).parent(".layui-input-block").append('<a target="_blank" href="' + res.filePath + '" class="showFile" style="padding: 9px;color:#f31414">' + res.FileName + '</a><i class="layui-icon removeIcon" style="color:#000">&#x1006;</i>')
               }

           }
           , error: function () {
               //请求异常回调
               layer.msg("请求异常", {icon:5})
           }
            });
        }


        //查看
        $("#renderList").on('click', '.showMsg', function () {
            var id = $(this).attr('data-id');
            var csid = $(this).attr('data-csid');
            var url = '/Upload/ViewList?id=' + id + '&csid=' + csid;
            //layer.open({
            //    type: 1,
            //    title: "资料查看",
            //    content: $("#showMsg"),
            //    area: ['700px', '450px'],
            //    success:function(layero, index){
            //        $.post('/Home/QueryById', { id: id }, function(res) {
            //            var arr =JSON.parse(res)[0];
            //            $('[name="project"]', layero).val(arr.project);
            //            $('[name="demandurl"]', layero).parents('div.layui-form-item').find('span.fileBox').empty().append('<a href="' + arr.demandurl + '" class="showFile" data-url="' + arr.demandurl + '" style="padding: 9px;color:#f31414" target="_blank">' + arr.demand + '</a> <i class="layui-icon removeIcon" style="color:#000">&#x1006;</i>')
            //        })
            //    }
            //})
            parent.xadmin.add_tab('资料上传', url);
        })
        //删除文件
        $("#showMsg").on('click', '.layui-form-item i.removeIcon', function () {
            var path = $(this).parent('span.fileBox').find('a.showFile').attr('data-url');
            debugger
            layer.confirm('是否确认删除？', { icon: 3, title: '提示' }, function (layerIndex) {
                $.post('/Home/DeleteDirectory', { path: path }, function (res) {
                    var data = JSON.parse(res);
                    console.log(data);
                    debugger
                    if (data.success) {
                        layer.msg(data.msg, { icon: 6 }, function () {
                            layer.close(layerIndex)
                        })
                    } else {
                        layer.msg(data.msg, { icon: 5 })
                    }
                })
            })
        })
        //执行一个laydate实例
        laydate.render({
            elem: '#start', //指定元素
            trigger:'click'
        });


        //文件路径提交

        $("#add").on('click', function () {
            layer.open({
                type: 1,
                title: "项目添加",
                content: $("#showMsg"),
                area: ['700px', '450px'],
                success: function () {
                    form.on('submit(formDemo)', function (data) {

                        var layerIndex;
                        $.ajax({
                            type: 'POST',
                            url: "/Home/Create",
                            beforeSend: function () {
                                layerIndex = layer.load();
                            },
                            data: {

                                project: data.field.project,
                            },
                            success: function (res) {
                                if (res.Success) {
                                    layer.msg(res.msg, { icon: 6, time: 2000 }, function () {
                                        layer.closeAll();
                                        list.init(1, 10);
                                        list.render(function (total) {
                                            list.page(total);
                                        });
                                    });
                                } else {
                                    layer.msg(res.msg, { icon: 5, time: 2000 }, function () {
                                        layer.closeAll();
                                    });
                                }
                            },
                            error: function (e) {
                                layer.msg(e, {icon:5})
                            },
                            complete: function () {

                            }
                        })
                        return false;
                    })
                },
                end: function (index, layero) {
                    $(".showMsg a.showFile", layero).remove();
                },

            })
        })
      });


       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要停用吗？',function(index){

              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

              }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
              }

          });
      }

      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              $(obj).parents("tr").remove();
              layer.msg('已删除!',{icon:1,time:1000});
          });
      }



      function delAll (argument) {
        var ids = [];

        // 获取选中的id
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });

        layer.confirm('确认要删除吗？'+ids.toString(),function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>
</body>
</html>